# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=icingaweb2-module-director
_pkgname=icinga-director
_module=${pkgname/*-/}
pkgver=1.10.2
pkgrel=1
pkgdesc="Configuration frontend for Icinga 2, integrated automation"
url="https://icinga.com/docs/icinga-director/latest/doc/01-Introduction/"
arch="noarch !armhf !armv7 !s390x !x86"
license="GPL-2.0-or-later"
_php=php82
depends="icingaweb2 $_php-curl $_php-pcntl icingaweb2-module-incubator"
options="!check"
install="$pkgname.pre-install $pkgname.post-install"
pkgusers="icingadirector"
pkggroups="icingaweb2"
subpackages="$pkgname-doc $_pkgname-openrc"
source="icingaweb2-module-director-$pkgver.tar.gz::https://github.com/Icinga/icingaweb2-module-director/archive/v$pkgver.tar.gz
$_pkgname.initd
$_pkgname.confd"

build() {
	return 0
}

package() {
	mkdir -p "$pkgdir/etc/icingaweb2/modules/$_module"
	mkdir -p "$pkgdir/usr/share/doc/$pkgname"
	mkdir -p "$pkgdir/usr/share/webapps/icingaweb2/modules/$_module"
	mkdir -p "$pkgdir/usr/share/webapps/icingaweb2/modules/$_module/contrib"
	cp -a application library public schema test \
		configuration.php module.info run.php \
		run-missingdeps.php register-hooks.php \
		"$pkgdir/usr/share/webapps/icingaweb2/modules/$_module"
	cp -a contrib/*-agent-installer \
		"$pkgdir/usr/share/webapps/icingaweb2/modules/$_module/contrib"
	cp -a doc "$pkgdir/usr/share/doc/$pkgname"
	chgrp -R $pkggroups "$pkgdir/etc/icingaweb2/modules/$_module"

	install -d -o $pkgusers -g $pkggroups -m 0750 "$pkgdir"/var/lib/icingadirector
	install -Dm644 "$srcdir"/$_pkgname.confd "$pkgdir"/etc/conf.d/$_pkgname
	install -Dm755 "$srcdir"/$_pkgname.initd "$pkgdir"/etc/init.d/$_pkgname
	chgrp -R $pkggroups "$pkgdir"/etc/icingaweb2/modules

	cat >"$pkgdir"/usr/share/doc/$pkgname/README.alpine <<EOF
You need to fix /etc/icingaweb2/modules/$_module with the owner of the user of your webserver

For nginx, as example:
	# chown -R nginx /etc/icingaweb2/modules/$_module
or
	# chown -R nobody /etc/icingaweb2/modules/$_module

For Apache:
	# chown -R apache /etc/icingaweb2/modules/$_module

For lighttpd:
	# chown -R lighttpd /etc/icingaweb2/modules/$_module

Remember to enable the module with:
	# icingacli module enable incubator
	# icingacli module enable $_module

EOF

}

openrc() {
	default_openrc
	depends="$_php-cli $_php-posix $_php-iconv $_php-sockets $_php-curl $_php-gettext"
}

sha512sums="
b301b71abada8c8722c03717a9def17c8ae53c951c83d5ef3a62f758fb93dd814d1b61d450987ddd0d8d3631145637dc6b26884134019e320cdd28cdedbc9794  icingaweb2-module-director-1.10.2.tar.gz
b3169954719c70e36dc9b103f7c00ece3bba5c91a4c5e732f2e740e5c696f0da82d42eee2cfbc41315db29eadcfb602c046875fb652fe45b6995eb28470871cb  icinga-director.initd
097a7cb19aeb6346a97e2a032d0be4891371aee0042822da4a65ad91f095e91eb41dda04a63cdcabffee0ad44c415670955c6cf47cfcf0eeda2a914c8563069b  icinga-director.confd
"
